package com.taobao.classloader.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taobao.classloader.ClassLoadStrategy;
import com.taobao.classloader.JarClassLoader;

public class NameListLoadStrategy implements ClassLoadStrategy {
	private static Logger	logger		= LoggerFactory.getLogger(NameListLoadStrategy.class);
	private List<String>	list;
	private boolean			excludable	= false;

	@Override
	public Class<?> loadClass(String className, JarClassLoader jarClassLoader, ClassLoader parentClassLoader) {
		Class<?> clazz = null;
		if (list != null && list.contains(className) && !excludable) {
			clazz = jarClassLoader.loadClassFromResource(className);
		}
		if (clazz == null) {
			try {
				clazz = parentClassLoader.loadClass(className);
			} catch (ClassNotFoundException e) {
				logger.debug("Can't load class:{} from parent classLoader.", className);
			}
		}
		return clazz;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	public boolean isExcludable() {
		return excludable;
	}

	public void setExcludable(boolean excludable) {
		this.excludable = excludable;
	}
}
